package com.situ.company.employee.service.impl;

import java.util.List;

import com.situ.company.employee.dao.IEmployeeDao;
import com.situ.company.employee.dao.impl.EmployeeDaoImpl;
import com.situ.company.employee.model.EmployeeModel;
import com.situ.company.employee.service.IEmployeeService;
import com.situ.company.util.MD5;

public class EmployeeServiceImpl implements IEmployeeService{

	private IEmployeeDao dao = new EmployeeDaoImpl();
	
	@Override
	public String insert(EmployeeModel model) {
		EmployeeModel mdb = selectModel(model);
		if(mdb != null) {
			return "repeat";
		}
		model.setPass(MD5.encode(model.getPass()));
		return dao.insert(model) + "";
	}

	@Override
	public String delete(EmployeeModel model) {
		return dao.delete(model)+"";
	}

	@Override
	public String update(EmployeeModel model) {
		return dao.updateActive(model)+"";
	}

	@Override
	public List<EmployeeModel> selectList(EmployeeModel model) {
		return dao.selectList(model);
	}

	@Override
	public EmployeeModel selectModel(EmployeeModel model) {
		return dao.selectModel(new EmployeeModel(model.getCode()));
	}

	
	
	@Override
	public String login(EmployeeModel model) {
		EmployeeModel mdb = selectModel(model);
		if(mdb == null) {
			return "0";
		}
		String pass = MD5.encode(model.getPass());
		return mdb.getPass().equals(pass)? "1" : "2";
	}

}












